<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';

require_once './include/advisory_db.php';
accessblock(array("Trial"));

$status = $_SESSION['status'];
$isTr = 'Trial' != $status && 'Standard' != $status;
$smarty->assign('isTr',$isTr);
//print_r($_SESSION);
$smarty->compile_check = true;

$smarty->display('header.tpl');
if($_GET[country]==''){
$_GET[country] = 211;
}
$smarty->assign('s',$_GET);
//jobupdate
$smarty->assign('state',$state);
$smarty->assign('country',$country);
$smarty->assign('industry',$jobcategory);
$smarty->assign('rec_findadvisor',$rec_findadvisor);
//print_r($orderby2);

// Name (First Last)/ Industry/ Specialty/ Service Location (State, Country)/ Email 
$order = " ORDER BY ad_id DESC";

if($_GET[action]=="search"){ 
	if($_GET[state]!='0'&&$_GET[state]!='') { $arr[] = " `ad_primarystate` = '".$_GET[state]."'  ";}
	if($_GET[country]!='0'&&$_GET[country]!='') { $arr[] = " `ad_primarycountry` = '".$_GET[country]."'  "; }
	if($_GET[industry]!='0'&&$_GET[industry]!='') { $arr[] = " `ad_industry` = '".$_GET[industry]."'  ";}
	if($_GET[specialty]!=''){ $arr[] = " `ad_specialty` like '%".$_GET[specialty]."%' ";}
	if($_GET[firstname]!='')  { $arr[] = " `ad_fname`  like '%".trim($_GET[firstname])."%'  ";}
	if($_GET[lastname]!=''){ $arr[] = " `ad_lname` like '%".trim($_GET[lastname])."%'  ";}

if($_GET[orderby]=='0'){$by = "ad_id";}
else{
	//$rec_findadvisor = array('-- SELECT ALL --','First Name','Last Name','Industry','Specialty','State','Country','Year of Exp.','Language');
	$ord   = array('','ad_fname','ad_lname','ad_industry','ad_specialty','ad_state','ad_country','ad_yrexp','ad_spoken');
	$by = $ord[$_GET[orderby]];
	$get[] = "orderby=$_GET[orderby]";
}

$where = "  WHERE 1=1 ";
//print_r($arr);
if(!empty($arr)){
	$implode  = @implode("AND", $arr);
	$implode  = " AND ".$implode;
	$where    .= $implode;
}


    $order = " ORDER BY $by DESC";
}
//echo "SELECT * FROM pa_advisory $where $order";
$nav = new buildNav;
$total = $DB->fetch_one_array("SELECT COUNT(*) AS count FROM pa_advisory $where");
$nav->total_result = $total[count];
$nav->execute("SELECT * FROM pa_advisory $where $order");

$page = $nav->pagenav();
//echo $sql2;

$i=0;
while($list2 = $DB->fetch_array($nav->sql_result)){
   $advlist[$i]              = $list2;
   $advlist[$i][ad_industry] = $jobcategory[$list2[ad_industry]];
   $state_    = ($list2[ad_primarystate]=="0")?'N/A':$state[$list2[ad_primarystate]];
   $country_  = ($list2[ad_primarycountry]=="0")?'N/A':$country[$list2[ad_primarycountry]];
   $advlist[$i][ad_location] = $state_.",".$country_;
   $advlist[$i][ad_name]     = $list2[ad_fname]." ".$list2[ad_lname];
   $i++;
}

$smarty->assign("advlist",$advlist);
$smarty->assign("page",$page);
if($err!=''){
$smarty->assign("err",$err);
}
$smarty->assign("search",$reg_data);
$smarty->display('allleft.tpl');
$smarty->display('findadvisor.tpl');
$smarty->display('footer.tpl');
?>